import { Injectable } from '@angular/core';
import { HttpClient } from '../../../../providers/httpClient';
import { Config } from '../../../../providers/config';
import _ from 'lodash';

@Injectable()
export class MarketingDailyDetailService {
	constructor(
		public httpClient: HttpClient,
		public config: Config,
	) { }
	// 获取邮件详情
	getDetailData(id, type) {
		let postBody;
		if (type == 'IMailHIS') {
			postBody = {
				"module": "Email",
				"method": "getMailInfoHisByBosid",
				"params": {
					"mailbosid": id,
					"logid": "fengjk"
				}
			};
		} else {
			postBody = {
				"module": "Email",
				"method": "getMailInfoByBosid",
				"params": {
					"mailbosid": id,
					"logid": "fengjk"
				}
			};
		}

		return this.httpClient.post(postBody);
	}

	// 删除邮件
	deleteEmail(id, type) {
		let postBody;
		if (type == 'IMailHIS') {
			postBody = {
				"module": "Email",
				"method": "mailInfoHisDelete",
				"params": {
					"ids": id
				}
			};
		} else {
			postBody = {
				"module": "Email",
				"method": "mailInfoDelete",
				"params": {
					"ids": id
				}
			};
		}

		return this.httpClient.post(postBody);
	}
	// 更新邮件状态
	updateMailInfoStat(id, params, isShow) {
		// 这个方法，一定要按顺序传！~ -。-
		let postBody = {
			"module": "Email",
			"method": "updateMailInfoStat",
			"params": {
				"ids": id
			}
		};
		_.assignIn(postBody.params, params);
		console.info(postBody);
		postBody.params['logid'] = "";
		return this.httpClient.post(postBody, {
			isShowLoading: isShow,
			isAlterError: isShow
		});
	}

	// 发送回执邮件
	sendEmail(data) {
		let postBody = {
			"module": "Email",
			"method": "sendEmail",
			"params": {
				"mailInfoDto": data
			}
		};
		return this.httpClient.post(postBody, {
			isShowLoading: false,
		});
	}

	// 更新邮件状态
	HisMailToInbox(id) {
		// 这个方法，一定要按顺序传！~ -。-
		let postBody = {
			"module": "Email",
			"method": "HisMailToInbox",
			"params": {
				"ids": id,
				"logid": ""
			}
		};
		return this.httpClient.post(postBody);
	}

	// 根据用户id，获取用户信息
	getContactDetailByLoginid(id) {
		let postBody = {
			"module": "OAServer",
			"method": "getContactDetailByLoginid",
			"params": {
				"username": id
			}
		};
		return this.httpClient.post(postBody, {
			isShowLoading: false,
			isAlterError: false
		});
	}
}
